//Lớp này chứa các thư viện sử dụng cho việc Format các Object như Grid, Combobox
//namespace ACRO.APP.UI
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.Utils;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;
using DevExpress.XtraTreeList.Menu;

namespace FormatLib 
{
    public class XtraControlFormat
    {
        /// <summary>
        /// Author: Dao xuan trung
        /// Purpose: Setup and bind the LookUpEdit
        /// </summary>
        /// <param name="LookUpEdit">LoockUpEdit Control Nam</param>
        /// <param name="ColumnName">Array of Column</param>
        /// <param name="ColumnHeader">Header of the Column</param>
        /// <param name="ColumnWidth">Column Width</param>
        /// <param name="DisplayMember">Display Column</param>
        /// <param name="ValueMember">Value column</param>
        /// <param name="dtSource">Data Source for bidding the lookupedit</param>
        public static void LookUpEditFormat(LookUpEdit LookUpEdit, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, string DisplayMember, string ValueMember, DataTable dtSource)
        {
            //FormatLib the LookUpEdit
            LookUpEdit.Properties.Columns.Clear();
            for (int i = 0; i < ColumnName.Length; i++)
            {
                LookUpEdit.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(ColumnName[i], ColumnHeader[i], ColumnWidth[i]));            
            }            
            //Set up the data binding
            LookUpEdit.Properties.DisplayMember = DisplayMember;
            LookUpEdit.Properties.ValueMember = ValueMember;
            LookUpEdit.Properties.DataSource = dtSource;
            LookUpEdit.Properties.NullText = "Select an item";
        }

        public static void LookUpEditFormat(LookUpEdit LookUpEdit, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, string DisplayMember, string ValueMember, bool[] Visible, DataTable dtSource)
        {
            for (int i = 0; i < ColumnName.Length; i++)
            {
                if (Visible[i] == true)
                {
                    LookUpEdit.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(ColumnName[i], ColumnHeader[i], ColumnWidth[i]));
                }
                else
                {
                    LookUpEdit.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(ColumnName[i], ColumnHeader[i], ColumnWidth[i],FormatType.None,"",false,HorzAlignment.Default));
                }
            }
            //Set up the data binding
            LookUpEdit.Properties.DisplayMember = DisplayMember;
            LookUpEdit.Properties.ValueMember = ValueMember;
            LookUpEdit.Properties.DataSource = dtSource;
            LookUpEdit.Properties.NullText = "Select an item";
        }

        public static void DateFormat(DateEdit date)
        {
            date.Properties.DisplayFormat.FormatString = "MM/yyyy";
            date.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            date.Properties.EditFormat.FormatString = "MM/yyyy";
            date.Properties.EditFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            date.Properties.Mask.EditMask = "MM/yyyy";
        }

        public static void LookUpEditFormat(LookUpEdit LookUpEdit, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, string DisplayMember, string ValueMember, DataTable dtSource, string NullText)
        {
            //FormatLib the LookUpEdit
            for (int i = 0; i < ColumnName.Length; i++)
            {
                LookUpEdit.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(ColumnName[i], ColumnHeader[i], ColumnWidth[i]));
            }
            //Set up the data binding
            LookUpEdit.Properties.DisplayMember = DisplayMember;
            LookUpEdit.Properties.ValueMember = ValueMember;
            LookUpEdit.Properties.DataSource = dtSource;
            LookUpEdit.Properties.NullText = NullText;
        }
        /// <summary>
        /// Author: Dao xuan trung
        /// Purpose: Setup and bind the LookUpEdit
        /// </summary>
        /// <param name="grd">Grid Name</param>
        /// <param name="ColumnName">Array of column Name</param>
        /// <param name="ColumnHeader">Array of Header name</param>
        /// <param name="ColumnWidth">Array of columnwidth</param>
        /// <param name="Align">Align column and header</param>
        /// 

        public static void GridFormat(GridControl grd, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, HorzAlignment[] Align, FormatInfo[] FormatInfo, DevExpress.Data.SummaryItemType?[] SummaryItemType, string[] SummaryFormat)
        {
            grd.Dock = DockStyle.Fill;
            grd.LookAndFeel.SkinName = "Money Twins";
            grd.LookAndFeel.UseDefaultLookAndFeel = false;
            grd.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            //Hiển thị Nevigator ở cuối trang để đếm số dòng
            grd.UseEmbeddedNavigator = true;
            // không cho cái Nevigator này thêm dòng
            grd.EmbeddedNavigator.Buttons.Append.Visible = true;
            grd.EmbeddedNavigator.Buttons.Remove.Visible = true;
            grd.EmbeddedNavigator.Buttons.Edit.Visible = true;
            grd.EmbeddedNavigator.Buttons.EndEdit.Visible = true;

            grd.Cursor = Cursors.Default;

            var view = (GridView)(grd.ViewCollection[0]);
            view.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedCell.Options.UseBackColor = true;
            view.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedRow.ForeColor = Color.Black;
            view.OptionsView.ShowGroupPanel = false;
            view.OptionsView.ShowIndicator = false;
            view.OptionsSelection.MultiSelect = true;
            view.OptionsBehavior.Editable = false;
            view.OptionsDetail.EnableDetailToolTip = true;
            view.OptionsView.ShowFooter = true;
            //GridOptionsDetail.EnableDetailToolTip

            for (int i = 0; i < ColumnName.Length; i++)
            {
                var a = new GridColumn { Caption = ColumnHeader[i], Name = ColumnName[i], FieldName = ColumnName[i] };
                a.Visible = true;
                a.VisibleIndex = i;
                a.OptionsColumn.AllowEdit = false;
                a.OptionsColumn.AllowFocus = true;
                a.OptionsColumn.AllowMove = true;
                if (SummaryItemType[i] != null)
                {
                    a.SummaryItem.SummaryType = (DevExpress.Data.SummaryItemType)SummaryItemType[i];
                    if (SummaryFormat[i] != null && SummaryFormat[i].Trim() != "")
                    {
                        a.SummaryItem.DisplayFormat = SummaryFormat[i];
                    }
                }

                view.Columns.Add(a);
            }
            view.OptionsView.ShowAutoFilterRow = true;

            //grd.Cursor = Cursors.Hand;
            for (int i = 0; i < view.Columns.Count; i++)
            {
                GridColumn col = view.Columns[i];
                col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                col.AppearanceHeader.Font = new Font("Arial", 9F, FontStyle.Bold);
                col.AppearanceCell.Font = new Font("Arial", 10F);
                col.AppearanceCell.Options.UseFont = true;
                col.Width = ColumnWidth[i];
                col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                col.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
                col.AppearanceCell.TextOptions.HAlignment = Align[i];
                col.OptionsColumn.AllowEdit = true;
                if (FormatInfo[i] != null && FormatInfo[i].FormatType != FormatType.None)
                {
                    col.DisplayFormat.FormatType = FormatInfo[i].FormatType;
                    if (FormatInfo[i].FormatString != "")
                    {
                        col.DisplayFormat.FormatString = FormatInfo[i].FormatString;
                    }
                }
            }
        }

        public static void GridFormat(GridControl grd, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, HorzAlignment[] Align, FormatInfo[] FormatInfo)
        {
            grd.Dock = DockStyle.Fill;
            grd.LookAndFeel.SkinName = "Money Twins";
            grd.LookAndFeel.UseDefaultLookAndFeel = false;
            grd.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            //Hiển thị Nevigator ở cuối trang để đếm số dòng
            grd.UseEmbeddedNavigator = true;
            // không cho cái Nevigator này thêm dòng
            grd.EmbeddedNavigator.Buttons.Append.Visible = false;
            grd.EmbeddedNavigator.Buttons.Remove.Visible = false;
            grd.EmbeddedNavigator.Buttons.Edit.Visible = false;
            grd.EmbeddedNavigator.Buttons.EndEdit.Visible = false;

            grd.Cursor = Cursors.Default;

            var view = (GridView)(grd.ViewCollection[0]);
            view.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedCell.Options.UseBackColor = true;
            view.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedRow.ForeColor = Color.Black;
            view.OptionsView.ShowFooter = false;
            view.OptionsView.ShowGroupPanel = false;
            view.OptionsView.ShowIndicator = true;
            view.OptionsSelection.MultiSelect = true;
            view.OptionsBehavior.Editable = true;
            view.OptionsDetail.EnableDetailToolTip = true;
            //GridOptionsDetail.EnableDetailToolTip

            for (int i = 0; i < ColumnName.Length; i++)
            {
                var a = new GridColumn { Caption = ColumnHeader[i], Name = ColumnName[i], FieldName = ColumnName[i] };
                a.Visible = true;
                a.VisibleIndex = i;
                a.OptionsColumn.AllowEdit = false;
                a.OptionsColumn.AllowFocus = false;
                a.OptionsColumn.AllowMove = false;
                view.Columns.Add(a);
            }
            view.OptionsView.ShowAutoFilterRow = true;

            //grd.Cursor = Cursors.Hand;
            for (int i = 0; i < view.Columns.Count; i++)
            {
                GridColumn col = view.Columns[i];
                col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                col.AppearanceHeader.Font = new Font("Arial", 9F, FontStyle.Bold);
                col.AppearanceCell.Font = new Font("Arial", 10F);
                col.AppearanceCell.Options.UseFont = true;
                col.Width = ColumnWidth[i];
                col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                col.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
                col.AppearanceCell.TextOptions.HAlignment = Align[i];
                col.OptionsColumn.AllowEdit = true;

                if (FormatInfo[i] != null && FormatInfo[i].FormatType != FormatType.None)
                {
                    col.DisplayFormat.FormatType = FormatInfo[i].FormatType;
                    if (FormatInfo[i].FormatString != "")
                    {
                        col.DisplayFormat.FormatString = FormatInfo[i].FormatString;
                    }
                }
            }
        }
        
        public static void GridFormat(GridControl grd, string[] ColumnName, string[] ColumnHeader)
        {
            grd.Dock = DockStyle.Fill;
            grd.LookAndFeel.SkinName = "Money Twins";
            grd.LookAndFeel.UseDefaultLookAndFeel = false;
            grd.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            //Hiển thị Nevigator ở cuối trang để đếm số dòng
            grd.UseEmbeddedNavigator = true;
            // không cho cái Nevigator này thêm dòng
            grd.EmbeddedNavigator.Buttons.Append.Visible = false;
            grd.EmbeddedNavigator.Buttons.Remove.Visible = false;
            grd.EmbeddedNavigator.Buttons.Edit.Visible = false;
            grd.EmbeddedNavigator.Buttons.EndEdit.Visible = false;

            grd.Cursor = Cursors.Default;

            var view = (GridView)(grd.ViewCollection[0]);
            view.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedCell.Options.UseBackColor = true;
            view.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedRow.ForeColor = Color.Black;
            view.OptionsView.ShowFooter = false;
            view.OptionsView.ShowGroupPanel = false;
            view.OptionsView.ShowIndicator = true;
            view.OptionsSelection.MultiSelect = false;
            view.OptionsBehavior.Editable = false;
            view.OptionsDetail.EnableDetailToolTip = true;
            //GridOptionsDetail.EnableDetailToolTip

            for (int i = 0; i < ColumnName.Length; i++)
            {
                var a = new GridColumn { Caption = ColumnHeader[i], Name = ColumnName[i], FieldName = ColumnName[i] };
                a.Visible = true;
                a.VisibleIndex = i;
                a.OptionsColumn.AllowEdit = false;
                a.OptionsColumn.AllowFocus = false;
                a.OptionsColumn.AllowMove = false;
                view.Columns.Add(a);
            }
            view.OptionsView.ShowAutoFilterRow = true;

            //grd.Cursor = Cursors.Hand;
            for (int i = 0; i < view.Columns.Count; i++)
            {
                GridColumn col = view.Columns[i];
                col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                col.AppearanceHeader.Font = new Font("Arial", 9F, FontStyle.Bold);
                col.AppearanceCell.Font = new Font("Arial", 10F);
                col.AppearanceCell.Options.UseFont = true;
                col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                col.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
                col.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
                col.OptionsColumn.AllowEdit = true;
            }
        }

        public static void GridFormat(GridControl grd, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, HorzAlignment[] Align)
        {
            grd.Dock = DockStyle.Fill;
            grd.LookAndFeel.SkinName = "Money Twins";               
            grd.LookAndFeel.UseDefaultLookAndFeel = false;
            grd.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            //Hiển thị Nevigator ở cuối trang để đếm số dòng
            grd.UseEmbeddedNavigator = true;
            // không cho cái Nevigator này thêm dòng
            grd.EmbeddedNavigator.Buttons.Append.Visible = false;
            grd.EmbeddedNavigator.Buttons.Remove.Visible = false;
            grd.EmbeddedNavigator.Buttons.Edit.Visible = false;
            grd.EmbeddedNavigator.Buttons.EndEdit.Visible = false;

            grd.Cursor = Cursors.Default;
           
            var view = (GridView)(grd.ViewCollection[0]);

            view.Columns.Clear();

            view.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedCell.Options.UseBackColor = true;
            view.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedRow.ForeColor = Color.Black;
            view.OptionsView.ShowFooter = false;
            view.OptionsView.ShowGroupPanel = false;
            view.OptionsView.ShowIndicator = true;
            view.OptionsSelection.MultiSelect = true;
            view.OptionsBehavior.Editable = true;
            view.OptionsDetail.EnableDetailToolTip = true;
            //GridOptionsDetail.EnableDetailToolTip

             for (int i = 0; i < ColumnName.Length; i++)
            {
                var a = new GridColumn { Caption = ColumnHeader[i], Name = ColumnName[i], FieldName = ColumnName[i] };
                a.Visible = true;
                a.VisibleIndex = i;
                a.OptionsColumn.AllowEdit = false;
                a.OptionsColumn.AllowFocus = false;
                a.OptionsColumn.AllowMove = false;
                view.Columns.Add(a);                
            }
            view.OptionsView.ShowAutoFilterRow = true;  
            
            //grd.Cursor = Cursors.Hand;
            for (int i = 0; i < view.Columns.Count; i++)
            {
                GridColumn col = view.Columns[i];                
                col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                col.AppearanceHeader.Font = new Font("Arial", 9F, FontStyle.Bold);                 
                col.AppearanceCell.Font = new Font("Arial", 10F);
                col.AppearanceCell.Options.UseFont = true;
                col.Width = ColumnWidth[i];
                col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                col.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
                col.AppearanceCell.TextOptions.HAlignment = Align[i];
                col.OptionsColumn.AllowEdit = true;    
            }
        }

        public static void GridFormat(GridControl grd, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, HorzAlignment[] Align, bool AllowEdit)
        {
            grd.Dock = DockStyle.Fill;
            grd.LookAndFeel.SkinName = "Money Twins";
            grd.LookAndFeel.UseDefaultLookAndFeel = false;
            grd.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            //Hiển thị Nevigator ở cuối trang để đếm số dòng
            grd.UseEmbeddedNavigator = true;
            // không cho cái Nevigator này thêm dòng
            grd.EmbeddedNavigator.Buttons.Append.Visible = AllowEdit;
            grd.EmbeddedNavigator.Buttons.Remove.Visible = AllowEdit;
            grd.EmbeddedNavigator.Buttons.Edit.Visible = AllowEdit;
            grd.EmbeddedNavigator.Buttons.EndEdit.Visible = AllowEdit;

            grd.Cursor = Cursors.Default;

            var view = (GridView)(grd.ViewCollection[0]);
            view.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedCell.Options.UseBackColor = true;
            view.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedRow.ForeColor = Color.Black;
            view.OptionsView.ShowFooter = false;
            view.OptionsView.ShowGroupPanel = false;
            view.OptionsView.ShowIndicator = true;
            view.OptionsSelection.MultiSelect = true;
            view.OptionsBehavior.Editable = true;
            view.OptionsDetail.EnableDetailToolTip = true;
            //GridOptionsDetail.EnableDetailToolTip

            for (int i = 0; i < ColumnName.Length; i++)
            {
                var a = new GridColumn { Caption = ColumnHeader[i], Name = ColumnName[i], FieldName = ColumnName[i] };
                a.Visible = true;
                a.VisibleIndex = i;
                a.OptionsColumn.AllowEdit = AllowEdit;
                a.OptionsColumn.AllowFocus = AllowEdit;
                a.OptionsColumn.AllowMove = AllowEdit;
                view.Columns.Add(a);
            }
            view.OptionsView.ShowAutoFilterRow = true;

            //grd.Cursor = Cursors.Hand;
            for (int i = 0; i < view.Columns.Count; i++)
            {
                GridColumn col = view.Columns[i];
                col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                col.AppearanceHeader.Font = new Font("Arial", 9F, FontStyle.Bold);
                col.AppearanceCell.Font = new Font("Arial", 10F);
                col.AppearanceCell.Options.UseFont = true;
                col.Width = ColumnWidth[i];
                col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                col.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
                col.AppearanceCell.TextOptions.HAlignment = Align[i];
                col.OptionsColumn.AllowEdit = true;
            }

        }

        public static void GridFormat(GridControl grd, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, bool[] Visible, HorzAlignment[] Align)
        {
            grd.Dock = DockStyle.Fill;
            grd.LookAndFeel.SkinName = "Money Twins";
            grd.LookAndFeel.UseDefaultLookAndFeel = false;
            grd.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            //Hiển thị Nevigator ở cuối trang để đếm số dòng
            grd.UseEmbeddedNavigator = true;
            // không cho cái Nevigator này thêm dòng
            grd.EmbeddedNavigator.Buttons.Append.Visible = false;
            grd.EmbeddedNavigator.Buttons.Remove.Visible = false;
            grd.EmbeddedNavigator.Buttons.Edit.Visible = false;
            grd.EmbeddedNavigator.Buttons.EndEdit.Visible = false;

            grd.Cursor = Cursors.Default;

            var view = (GridView)(grd.ViewCollection[0]);
            view.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedCell.Options.UseBackColor = true;
            view.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedRow.ForeColor = Color.Black;
            view.OptionsView.ShowFooter = false;
            view.OptionsView.ShowGroupPanel = false;
            view.OptionsView.ShowIndicator = true;
            view.OptionsSelection.MultiSelect = true;
            view.OptionsBehavior.Editable = true;
            view.OptionsDetail.EnableDetailToolTip = true;
            //GridOptionsDetail.EnableDetailToolTip

            for (int i = 0; i < ColumnName.Length; i++)
            {
                var a = new GridColumn { Caption = ColumnHeader[i], Name = ColumnName[i], FieldName = ColumnName[i] };
                a.Visible = Visible[i];
                if(Visible[i] == true)
                    a.VisibleIndex = i;
                a.OptionsColumn.AllowEdit = false;
                a.OptionsColumn.AllowFocus = false;
                a.OptionsColumn.AllowMove = false;
                view.Columns.Add(a);
            }
            view.OptionsView.ShowAutoFilterRow = true;

            //grd.Cursor = Cursors.Hand;
            for (int i = 0; i < view.Columns.Count; i++)
            {
                GridColumn col = view.Columns[i];
                col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                col.AppearanceHeader.Font = new Font("Arial", 9F, FontStyle.Bold);
                col.AppearanceCell.Font = new Font("Arial", 10F);
                col.AppearanceCell.Options.UseFont = true;
                col.Width = ColumnWidth[i];
                col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                col.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
                col.AppearanceCell.TextOptions.HAlignment = Align[i];
                col.OptionsColumn.AllowEdit = false;

            }

        }

        public static void GridFormat(GridControl grd, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, HorzAlignment[] Align, bool[] AllowEdit)
        {
            grd.Dock = DockStyle.Fill;
            grd.LookAndFeel.SkinName = "Money Twins";
            grd.LookAndFeel.UseDefaultLookAndFeel = false;
            grd.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            //Hiển thị Nevigator ở cuối trang để đếm số dòng
            grd.UseEmbeddedNavigator = true;
            // không cho cái Nevigator này thêm dòng
            grd.EmbeddedNavigator.Buttons.Append.Visible = false;
            grd.EmbeddedNavigator.Buttons.Remove.Visible = false;
            grd.EmbeddedNavigator.Buttons.Edit.Visible = false;
            grd.EmbeddedNavigator.Buttons.EndEdit.Visible = false;

            grd.Cursor = Cursors.Default;

            var view = (GridView)(grd.ViewCollection[0]);
            view.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedCell.Options.UseBackColor = true;
            view.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            view.Appearance.FocusedRow.ForeColor = Color.Black;
            view.OptionsView.ShowFooter = false;
            view.OptionsView.ShowGroupPanel = false;
            view.OptionsView.ShowIndicator = true;
            view.OptionsSelection.MultiSelect = true;
            view.OptionsBehavior.Editable = true;
            view.OptionsDetail.EnableDetailToolTip = true;
            //GridOptionsDetail.EnableDetailToolTip

            for (int i = 0; i < ColumnName.Length; i++)
            {
                var a = new GridColumn { Caption = ColumnHeader[i], Name = ColumnName[i], FieldName = ColumnName[i] };
                a.Visible = true;
                a.VisibleIndex = i;
                a.OptionsColumn.AllowEdit = AllowEdit[i];
                a.OptionsColumn.AllowFocus = false;
                a.OptionsColumn.AllowMove = false;                
                view.Columns.Add(a);
            }
            view.OptionsView.ShowAutoFilterRow = true;

            //grd.Cursor = Cursors.Hand;
            for (int i = 0; i < view.Columns.Count; i++)
            {
                GridColumn col = view.Columns[i];
                col.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
                col.AppearanceHeader.Font = new Font("Arial", 9F, FontStyle.Bold);
                col.AppearanceCell.Font = new Font("Arial", 10F);
                col.AppearanceCell.Options.UseFont = true;
                col.Width = ColumnWidth[i];
                col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                col.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
                col.AppearanceCell.TextOptions.HAlignment = Align[i];
            }
        }


        public static void TreeFormat(TreeList treeList, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, HorzAlignment[] Align)//, string[] ColumnName, string[] ColumnHeader, int[] ColumnWidth, HorzAlignment[] Align)
        {

            treeList.Dock = DockStyle.Fill;
            treeList.LookAndFeel.SkinName = "Money Twins";
            treeList.LookAndFeel.UseDefaultLookAndFeel = false;
            treeList.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            treeList.Cursor = Cursors.Default;
            treeList.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            treeList.Appearance.FocusedCell.Options.UseBackColor = true;
            treeList.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            treeList.Appearance.FocusedRow.ForeColor = Color.Black;
            treeList.OptionsView.ShowColumns = true;
            treeList.OptionsView.ShowRowFooterSummary = false;
            treeList.OptionsView.ShowIndicator = false;
            treeList.OptionsSelection.MultiSelect = true;
            treeList.OptionsBehavior.Editable = true;
            treeList.OptionsBehavior.EnableFiltering=true;

            treeList.Appearance.HeaderPanel.Font = new Font("Arial", 9F, FontStyle.Bold);
            treeList.Appearance.Row.Font = new Font("Arial", 10F);

            for (int i = 0; i < ColumnName.Length; i++)
            {
                DevExpress.XtraTreeList.Columns.TreeListColumn a = treeList.Columns.Add();                               
                a.Visible = true;
                a.FieldName = ColumnName[i];
                a.Caption = ColumnHeader[i];
                a.Width = ColumnWidth[i];
                a.OptionsColumn.AllowEdit = false;
                a.OptionsColumn.AllowFocus = false;
                a.OptionsColumn.AllowMove = true;
                a.AppearanceCell.TextOptions.HAlignment = Align[i];
                a.OptionsColumn.AllowSort = true;
                a.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;
               
            }          
        }

        public static void TreeFormat(TreeList treeList, string[] ColumnName, string[] ColumnHeader)
        {

            treeList.Dock = DockStyle.Fill;
            treeList.LookAndFeel.SkinName = "Money Twins";
            treeList.LookAndFeel.UseDefaultLookAndFeel = false;
            treeList.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Skin;
            treeList.Cursor = Cursors.Default;
            treeList.Appearance.FocusedCell.BackColor = Color.FromArgb(255, 255, 192);
            treeList.Appearance.FocusedCell.Options.UseBackColor = true;
            treeList.Appearance.FocusedRow.BackColor = Color.FromArgb(255, 255, 192);
            treeList.Appearance.FocusedRow.ForeColor = Color.Black;
            treeList.OptionsView.ShowColumns = true;
            treeList.OptionsView.ShowRowFooterSummary = false;
            treeList.OptionsView.ShowIndicator = false;
            treeList.OptionsSelection.MultiSelect = true;
            treeList.OptionsBehavior.Editable = true;
            treeList.OptionsBehavior.EnableFiltering = true;

            treeList.Appearance.HeaderPanel.Font = new Font("Arial", 9F, FontStyle.Bold);
            treeList.Appearance.Row.Font = new Font("Arial", 10F);

            for (int i = 0; i < ColumnName.Length; i++)
            {
                DevExpress.XtraTreeList.Columns.TreeListColumn a = treeList.Columns.Add();
                a.Visible = true;
                a.FieldName = ColumnName[i];
                a.Caption = ColumnHeader[i];
                a.OptionsColumn.AllowEdit = true;
                a.OptionsColumn.ReadOnly = false;
                a.OptionsColumn.AllowFocus = true;
                a.OptionsColumn.AllowMove = true;
                a.OptionsColumn.AllowSort = true;
                a.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap;

            }
        }

        public static void DialogFormat(XtraForm form)
        {
            form.MaximizeBox = false;
            form.MinimizeBox = false;
            form.StartPosition = FormStartPosition.CenterParent;
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
        }
    }
}

